<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:74:"D:\phpstudy_pro\WWW\tpshop\public/../application/admin\view\goods\add.html";i:1580870625;s:61:"D:\phpstudy_pro\WWW\tpshop\application\admin\view\layout.html";i:1580870358;}*/ ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?php echo $title; ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link href="/static/admin/css/main.css" rel="stylesheet" type="text/css"/>
    <link href="/static/admin/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/static/admin/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css"/>
    <script src="/static/admin/js/jquery-1.8.1.min.js"></script>
    <script src="/static/admin/js/bootstrap.min.js"></script>
    <script src="/static/admin/js/highcharts.js"></script>
    <script src="/static/admin/js/exporting.js"></script>
    <script src="/static/admin/js/draw.js"></script>

</head>
<body>

    <!-- 上 -->
    <div class="navbar">
        <div class="navbar-inner">
            <div class="container-fluid">
                <ul class="nav pull-right">
                    <li id="fat-menu" class="dropdown">
                        <a href="#" id="drop3" role="button" class="dropdown-toggle" data-toggle="dropdown">
                            <i class="icon-user icon-white"></i> <?php echo \think\Session::get('info.nickname'); ?>
                            <i class="icon-caret-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a tabindex="-1" href="javascript:void(0);">修改密码</a></li>
                            <li class="divider"></li>
                            <li><a tabindex="-1" href="<?php echo url('admin/Base/logout'); ?>">安全退出</a></li>
                        </ul>
                    </li>
                </ul>
                <a class="brand" href="index.html"><span class="first">后台管理系统</span></a>
                <ul class="nav">
                    <li class="active"><a href="javascript:void(0);">首页</a></li>
<!--                    <li><a href="javascript:void(0);">系统管理</a></li>-->
<!--                    <li><a href="javascript:void(0);">权限管理</a></li>-->
                </ul>
            </div>
        </div>
    </div>
    <!-- 左 -->
    <div class="sidebar-nav">

        <?php foreach($top_nav as $k=>$v): ?>
            <a href="#error-menu<?php echo $k; ?>" class="nav-header collapsed" data-toggle="collapse">
                <i class="icon-exclamation-sign"></i>
                <?php echo $v['auth_name']; ?>
            </a>
            <ul id="error-menu<?php echo $k; ?>" class="nav nav-list collapse in">
                <?php foreach($down_nav as $m): if($m['pid'] == $v['id']): ?>
                        <li>
                            <a href="<?php echo url('admin/'.$m['auth_c'] . '/' . $m['auth_a']); ?>">
                                <?php echo $m['auth_name']; ?>
                            </a>
                        </li>
                    <?php endif; endforeach; ?>
            </ul>
        <?php endforeach; ?>

    </div>
<script src="/plugins/ueditor/ueditor.config.js"></script>
<script src="/plugins/ueditor/ueditor.all.min.js"></script>
<script src="/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
<!-- 右 -->
    <div class="content">
        <div class="header">
            <h1 class="page-title">商品新增</h1>
        </div>

        <!-- add form -->
        <form action="<?php echo url('admin/goods/insert'); ?>" method="post" id="tab" enctype="multipart/form-data">
            <?php echo token(); ?>
            <ul class="nav nav-tabs">
              <li role="presentation" class="active"><a href="#basic" data-toggle="tab">基本信息</a></li>
              <li role="presentation"><a href="#desc" data-toggle="tab">商品描述</a></li>
              <li role="presentation"><a href="#attr" data-toggle="tab">商品属性</a></li>
              <li role="presentation"><a href="#pics" data-toggle="tab">商品相册</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane fade in active" id="basic">
                    <div class="well">
                        <label>商品名称：</label>
                        <input type="text" name="goods_name" value="" class="input-xlarge">
                        <label>商品价格：</label>
                        <input type="text" name="goods_price" value="" class="input-xlarge">
                        <label>商品数量：</label>
                        <input type="text" name="goods_number" value="" class="input-xlarge">
                        <label>商品logo：</label>

                        <input type="file" name="goods_logo" value="" class="input-xlarge">

                        <label>商品分类：</label>
                        <select name="" id="one" class="input-xlarge">
                            <option value="">请选择一级分类</option>
                            <?php foreach($cateone as $v): ?>
                                <option value="<?php echo $v['id']; ?>" name='cate_id'><?php echo $v['cate_name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                        <select name="" id="two" class="input-xlarge">
                            <option value="">请选择二级分类</option>
                        </select>
                        <select name="cate_id" id="three" class="input-xlarge">
                            <option value="">请选择三级分类</option>
                        </select>
                    </div>
                </div>
                <div class="tab-pane fade in" id="desc">
                    <div class="well">
                        <label>商品简介：</label>
                        <textarea id="editor" name="goods_body" style="width:1024px;height:500px;"></textarea>
                    </div>
                </div>
                <div class="tab-pane fade in" id="attr">
                    <div class="well">
                        <label>商品类型：</label>
                        <select name="type_id" class="input-xlarge">
                            <option value="">请选择</option>
                            <?php foreach($type as $v): ?>
                                <option value="<?php echo $v['id']; ?>"><?php echo $v['type_name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                        <div id="attrs"></div>
                    </div>
                </div>
                <div class="tab-pane fade in" id="pics">
                    <div class="well">
                        <div>[<a href="javascript:void(0);" class="add">+</a>]商品图片：<input type="file" name="goods_pics[]" value="" class="input-xlarge"></div>
                    </div>
                </div>
                <button class="btn btn-primary" type="submit">保存</button>
            </div>
        </form>

    </div>
    <script type="text/javascript">

        // 商品类型添加
        $("select[name=type_id]").change(function(){
            // 清空当前元素的内容
            $("#attrs").html("");

            var id = $(this).val();

            if(id == "") return;

            $.ajax({
                url:"<?php echo url('admin/attribute/getTree'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000){
                        alert(res.msg);
                        return;
                    }
                    // 显示属性名称 遍历数组 拼接数组
                    // 定义空的变量 用来接受数据和 最后追加到页面
                    var str = "";
                    $.each(res.data,function(i,v){
                        str += "<label>"+ v.attr_name +"</label>";

                        // 判断当前为什么方式
                        if(v.attr_input_type == 0){

                            str += "<input type='text' name='attr_value["+ v.id +"][]' class='input-xlarge'/>"
                        }else if(v.attr_input_type == 1){

                            str += "<select name='attr_value["+ id +"][]'>";
                                str += "<option >请选择</option>";
                                $.each(v.attr_values,function(index,value){
                                    str += "<option value='"+ value + "'>"+ value +"</option>";
                                });
                            str += "</select>";
                        }else{

                            $.each(v.attr_values,function(index,value){
                                str += "<input name='attr_value["+ v.id +"][]' type='checkbox' value='"+ value +"' />" + value;
                            })
                        }
                    })

                    $("#attrs").append(str);
                }
            })
        })

        // 三级分类
        $("#one").change(function(){
            $("#two").html("<option value=''>请选择二级分类</option>");
            $("#three").html("<option value=''>请选择二级分类</option>");
            var id = $("#one").val();

            if(id == "") return;
            // 请求ajax
            $.ajax({
                url:"<?php echo url('admin/goods/getTree'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000)
                    {
                        alert("请求错误");
                        return;
                    }

                    var html = "";
                    $.each(res.data,function(i,v){
                        html += "<option name='cate_id' value='"+ v.id + "'>" + v.cate_name+ "</option>";
                    })
                    $("#two").append(html);
                }
            })
        })

        $("#two").change(function(){
            $("#three").html("<option value=''>请选择三级分类</option>");

            var id = $("#two").val();

            if(id == "") return;
            // 请求ajax
            $.ajax({
                url:"<?php echo url('admin/goods/getTree'); ?>",
                data:"id="+id,
                success:function(res){
                    if(res.code != 10000)
                    {
                        alert("请求错误");
                        return;
                    }

                    var html = "";

                    $.each(res.data,function(i,v){
                        html += "<option name='cate_id' value='"+ v.id + "'>" + v.cate_name+ "</option>";
                    });

                    $("#three").append(html);
                }
            })
        })
        // 三级分类

        // 引入ueditor编辑器
        UE.getEditor('editor');

        //
        $('.add').click(function(){
            var add_div = '<div>[<a href="javascript:void(0);" class="sub">-</a>]商品图片：<input type="file" name="goods_pics[]" value="" class="input-xlarge"></div>';
            $(this).parent().after(add_div);
        });
        $('.sub').live('click',function(){
            $(this).parent().remove();
        });
    </script>


</body>
</html>